package formBean;


import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

import util.Util;

public class EmployeeAc extends FormBean {
	
	private String firstName;	
	private String lastName;	
	private String userName;	
	private String password;	
	private String confirm;
	
	public String getFirstName() {
		return firstName;
	}
	
	public String getLastName() {
		return lastName;
	}
	
	public String getUserName() {
		return userName;
	}
	
	public String getPassword() {
		return password;
	}
	
	 public String getConfirm() {
		return confirm;
    }
	
	public void setFirstName(String s) {
		firstName = trimAndConvert(s, "<>\"");
	}
	
	public void setLastName(String s) {
		lastName = trimAndConvert(s, "<>\"");
	}
	
	public void setUserName(String s) {
		userName = trimAndConvert(s, "<>\"");
	}
	
	public void setPassword(String s) {
		password = s.trim();
	}
	
	 public void setConfirm(String s) {
		confirm = s.trim();
    }

	@Override
	public List<String> getValidationErrors() {
		ArrayList<String> errors = new ArrayList<String>();
		
		Util.checkNullAndLength("First name", firstName, 15, errors);
		Util.checkNullAndLength("Last name", lastName, 15, errors);
		Util.checkNullAndLength("User name", userName, 15, errors);
		Util.checkNullAndLength("Password", password, 40, errors);
		
		if (errors.size()> 0) {
			return errors;
		}
		
		if (!password.equals(confirm)) {
		    errors.add("Passwords are not the same");
		}
		
		if (!Util.isValidUsername(this.firstName)) {
			errors.add("First name is not a valid one. It should not contain special characters and should at least have 3 characters.");
		}
		
		if (!Util.isValidUsername(this.lastName)) {
			errors.add("Last name is not a valid one. It should not contain special characters and should at least have 3 characters");
		}
		
		if (!Util.isValidUsername(this.userName)) {
			errors.add("User name is not a valid one. It should not contain special characters and should at least have 3 characters");
		}
		
		Util.checkInjection("firstName", firstName, errors);
		Util.checkInjection("lastName", lastName, errors);
		Util.checkInjection("userName", userName, errors);
		Util.checkInjection("password", password, errors);
		
		return errors;
	}
}
